package com.lz.football.module.fameHall.item
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.FameHall.vo.FameHallVo;
	import com.lz.football.module.club.item.BaseItem;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.text.TextField;
	
	public class FameHallItem extends BaseItem
	{
		
		/**
		 *名称  
		 */
		private var hameName:TextField;
		/**
		 *图标  
		 */
		private var icon:MovieClip;
		/**
		 *闪烁效果(有球员可以放入荣誉堂) 
		 */
		private var flickerEff:MovieClip;
		/**
		 *可以放置球员 
		 */
		private var num:TextField;
		
		
		public function FameHallItem()
		{
			super();
		}
		override public function initUI(view:Object=null):void
		{
			_skin = Reflection.createInstance("com.lz.modul.famehall.fameItem");
			this.addChild(_skin);
			_skin.gotoAndStop(1);
			hameName = _skin.hameName;
			icon = _skin.icon.icon;
			flickerEff = _skin.flickerEff;
			num = flickerEff.num;
			num.text = "";
			flickerEff.gotoAndStop(1)
			flickerEff.visible = false;
			super.initUI();
			
			
		}
		/**
		 * 设置三种状态 1 全部未开启，2 有开启 3 有球员使用开启 
		 * @param $vo
		 * 
		 */		
		public function setDate($vo:FameHallVo):void
		{
			
			super.data = $vo;
		
			
			//判断是否有开启的球员
			if($vo.active == 1)//激活
			{
				_skin.gotoAndStop(3);
				flickerEff.gotoAndStop(1)
				flickerEff.visible = false;
			}else
			{
				
				//是否有球员开启过
				var isOpen:Boolean = false;
				
				if($vo.palyerid_1 == $vo.starid1)
				{
					isOpen = true;
				}
				if($vo.palyerid_2 == $vo.starid2)
				{
					isOpen = true;
				}
				if($vo.palyerid_3 == $vo.starid3)
				{
					isOpen = true;
				}
				if(isOpen)
				{
					_skin.gotoAndStop(1);
				}else
				{
					_skin.gotoAndStop(2);
				}
				//是否有球员可以放置，有则有闪烁效果
				var arr:Array=[];
				var n:int = 0;//可放置的球员格
				var tempList:Array;
				if($vo.palyerid_1 != $vo.starid1)
				{
					tempList = AppData.getInstance().bagDataManager.getStarsGoodsByStarId($vo.palyerid_1);
					arr = arr.concat(tempList);
					if(tempList.length > 0)n++;
				}
				if($vo.palyerid_2 != $vo.starid2)
				{
					tempList =  AppData.getInstance().bagDataManager.getStarsGoodsByStarId($vo.palyerid_2);
					arr = arr.concat(tempList);
					if(tempList.length > 0)n++;
				}
				if($vo.palyerid_3 != $vo.starid3)
				{
					tempList =  AppData.getInstance().bagDataManager.getStarsGoodsByStarId($vo.palyerid_3);
					arr = arr.concat(tempList);
					if(tempList.length > 0)n++;
				}
				if(n >0)num.text  = "" + n;
				if((arr == null|| arr.length==0) && !isOpen)//还没有开启，并没有球员可以放置
				{
					_skin.gotoAndStop(2);
					flickerEff.gotoAndStop(1)
					flickerEff.visible = false;
				}else
				{
					_skin.gotoAndStop(1);
					if(arr.length == 0)
					{
						flickerEff.gotoAndStop(1)
						flickerEff.visible = false;
					}else
					{
//						flickerEff.gotoAndPlay(1)
						flickerEff.visible = true;
					}
				}
				
			}
				
			
			//判断是否有已经开启的球员
			
				
			hameName = _skin.hameName;
			hameName.text = $vo.huname + "";
			DisplayObjectUtil.removeAllChildren(icon);
			var b:BitmapData = Reflection.createInstance("fameHall_"+$vo.header);
			var bitmap:Bitmap = new Bitmap(b);
			icon.addChild(bitmap);
			
		}
		override public function set select(value:Boolean):void
		{
			super.select = value;
			if(flickerEff != null)
			{
//				flickerEff.gotoAndStop(1)
//				flickerEff.visible = false;
			}
		}
	}
}